package com.yiwyn;

import com.yiwyn.utils.RSAUtil;
import sun.java2d.pipe.SpanIterator;

public class Main {
    public static void main(String[] args) throws Exception {


        //服务端公钥
        String serverPublicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKw+tmOJqQyGcz9MXxM8AIhYUIYPT1nMon6GN+HRmSkjIZSiLlpNQj0DLaHBTHyUvwP6q+Y8eL0VOczKuefqj6MCAwEAAQ==";
        //服务端私钥
        String serverPrivateKey = "MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEArD62Y4mpDIZzP0xfEzwAiFhQhg9PWcyifoY34dGZKSMhlKIuWk1CPQMtocFMfJS/A/qr5jx4vRU5zMq55+qPowIDAQABAkB2LBRwGAseJ8Q74ka8aIcpBAZC45AaWPYG/kiqqmV9PZegGl5TB7Ky8EsAwNwLp8QVMby1Gga3mkfCqzdDuhgZAiEA3CS3C+LvE9uvTUKvVYUtg/qD7rtzJIqepDxvnijeSN8CIQDITMiT8sDNEVgrc8RftrsmTpFVi4numPQEaBdSNKKdvQIgHEX24Gbv76v6UsDqxeAJ3XZyNVoLyrim8U71wulayx8CIQCluvKTh96DTwCXI3iugXGkpomWMJj2NNRi+QWi3S5YOQIhAJhj0Qvda9Qh+AnoNz0uoUVaoYTHXBNW380KC4joeFVr";

        //客服端加密
        String content = RSAUtil.encrypt("测试", serverPublicKey);
        System.out.println(content);
        //output： R7VQg/vEgDjAUTm7M+gdm4kvMlRUACQtIb2EikXiH+kksu5T5qpEBcnsn54MbVDTl7HciVpaXLOADA6H61mJag==

        //服务端私钥解密
        String decrypt = RSAUtil.decrypto("HGLy+xMBi+l7wo9avzs26Q7zjqyQUrm23NWYMxYQ+SurvCPMhCuDJNFuT9x0DawN+8pC3+U2sYsAg7A0fZwQhg==",
                serverPrivateKey);

        System.out.println(decrypt);
        //output：测试


        System.out.println("============加签============");
        System.out.println("============验签============");

        //客户端公钥
        String clientPublicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAOBjDTVH9pmOysrZDyokk/rd6eG2nZk5B0IE2+VYuqH8pmOWqXKw/eRy0XPaWFZEMiIt3N7mO2vvfpglmY4QFeUCAwEAAQ==";
        //客户端私钥
        String clientPrivateKey = "MIIBVwIBADANBgkqhkiG9w0BAQEFAASCAUEwggE9AgEAAkEA4GMNNUf2mY7KytkPKiST+t3p4badmTkHQgTb5Vi6ofymY5apcrD95HLRc9pYVkQyIi3c3uY7a+9+mCWZjhAV5QIDAQABAkEAroB5qiEQB3XEAiLyJy0RJDzmgZG6WInAOjh7Jo5tfkD/TxRdKyrTS0mQbQ/GmA7LAtnXeG4X7ellSyuy2Bk3IQIhAP69qTx47QfSfyEPnLJFVwmR/qZq9wRMc1Mh25BLOuR9AiEA4X77WlK3HY3i+XIl6ZL8gMBW3I1pnZRHqOe0k3DfO4kCIQCRAPLpmkgKcNauwg1HKNM/flw+7JpJVx86TgaGX1xZnQIhALYv+DjT16sDNj1AIq2C2ovT2to7TvfIE9W9z0HI0jOxAiEA58MRSM8L26EWfSzpiggeH4YvmqOZhx04IFO1YLRWzWQ=";

        String data = "签名";
        //客户端使用私钥加签
        String signValue = RSAUtil.sign(data, clientPrivateKey);
        System.out.println("签名的值:" + signValue);
        //服务端使用公钥验签
        Boolean b = RSAUtil.signVerify(data, signValue, clientPublicKey);
        System.out.println("验签结果：" + b);
        //output：true
    }
}

